package com.example.edu_service.controller;


import com.example.commonutils.R;
import com.example.edu_service.entity.EduChapter;
import com.example.edu_service.entity.chapter.Chapter;
import com.example.edu_service.service.EduChapterService;
import com.example.edu_service.service.EduCourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 课程 前端控制器
 * </p>
 *
 * @author testjava
 * @since 2021-08-02
 */
@RestController
@RequestMapping("/edu_service/edu_chapter")

public class EduChapterController {

    @Autowired
     private EduChapterService chapterService;

    @GetMapping("getChapter/{courseId}")
    public R getChapter(@PathVariable String courseId){

        List<Chapter> list= chapterService.getChapterById(courseId);

        return R.ok().data("allChapter",list);
    }

    @PostMapping("addChapter")
    public R addChapter(@RequestBody EduChapter eduChapter){

        chapterService.save(eduChapter);
        return R.ok();
    }

    @GetMapping("getChapterInfo/{chapterId}")
    public R getChapterInfo(@PathVariable String chapterId){
        EduChapter chapter = chapterService.getById(chapterId);
        return R.ok().data("chapter",chapter);
    }


    @PostMapping("updateChapter")
    public R updateChapter(@RequestBody EduChapter eduChapter){

        chapterService.updateById(eduChapter);
        return R.ok();
    }

    @DeleteMapping("deleteChapter/{chapterId}")
    public R deleteChapter(@PathVariable String chapterId){

        boolean flag = chapterService.deleteChapter(chapterId);
        return R.ok();
    }



}

